package auxiliary;
import java.awt.Container;
import java.awt.Image;
import java.awt.Toolkit;
import java.net.URL;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTabbedPane;
import javax.swing.JToolBar;
import javax.swing.SwingUtilities;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import modulos.PanelConfirmar;
import modulos.PanelFuncionario;
import modulos.PanelMaquinaria;
import modulos.PanelMensuales;
import modulos.PanelPlan;
import modulos.PanelProducto;

public class GercoPlaneacion extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	JButton planbutton, funcionariobutton, maquinabutton, produccionbutton;
	JToolBar toolbar;
	PanelPlan planpanel;
	PanelFuncionario funcionariopanel;
	// ButtonToolbarHandler handler;
	PanelMaquinaria maquinapanel;
	PanelProducto productopanel;
	PanelMensuales mensualespanel;
	PanelConfirmar confirmarpanel;
	int monthselection;
	int yearselection;
	int dayselection;

	Container contentPane;

	public GercoPlaneacion() {
		super("Planeamiento Gerco");
		setSize(1024, 576);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setVisible(true);
		setResizable(false);

		URL imgURL = ClassLoader.getSystemResource("images/plan.png");
		Image image = Toolkit.getDefaultToolkit().getImage(imgURL);

		ImageIcon planicon = new ImageIcon(image);
		
		Image img = planicon.getImage();  
		Image newimg = img.getScaledInstance(20, 20,  java.awt.Image.SCALE_SMOOTH);  
		planicon = new ImageIcon(newimg);
		
		this.setIconImage(newimg);
		
		contentPane = getContentPane();

		planpanel = new PanelPlan(this);


		funcionariopanel = new PanelFuncionario();

		maquinapanel = new PanelMaquinaria();

		productopanel = new PanelProducto();

		mensualespanel = new PanelMensuales();

		confirmarpanel = new PanelConfirmar(this);

		SwingUtilities.invokeLater(new Runnable() {
			public void run() {

				JTabbedPane tabbedPane = new JTabbedPane();
				tabbedPane.addTab("Plan", null, planpanel, null);
				tabbedPane.addTab("Necesidades Semanales", null,
						mensualespanel, null);
				tabbedPane
						.addTab("Produccion Real", null, confirmarpanel, null);
				tabbedPane.setSelectedIndex(0);
				
				tabbedPane.addTab("Maquinaria", null, maquinapanel, null);
				
				tabbedPane.addTab("Funcionarios", null, funcionariopanel, null);

				tabbedPane.addTab("Productos", null, productopanel, null);

				tabbedPane.addChangeListener(new ChangeListener() {
					// This method is called whenever the selected tab changes
					public void stateChanged(ChangeEvent evt) {
						// JTabbedPane pane = (JTabbedPane) evt.getSource();

						/*planpanel.setMonthIndex(monthselection);
						planpanel.setYearIndex(yearselection);
						planpanel.setDayIndex(dayselection);
						
						confirmarpanel.setMonthIndex(monthselection);
						confirmarpanel.setYearIndex(yearselection);
						confirmarpanel.setDayIndex(dayselection);*/
						
						funcionariopanel.updateTable();
						maquinapanel.updateTable();
						productopanel.updateTable();
						mensualespanel.updateTable();
						
						if(confirmarpanel.getConfirmadoStatus()) {
							planpanel.updateStatus();
							confirmarpanel.resetConfirmadoStatus();
						}
						
						if(planpanel.getActualizarStatus()) {
							confirmarpanel.updateStatus();
							planpanel.resetActualizarStatus();
							//confirmarpanel.resetConfirmadoStatus();
						}
						
						// planpanel.set
					}

				});

				contentPane.add(tabbedPane);

				invalidate();
				validate();
			}
		});

	}
	
	public void setYearSelection(int year) {
		this.yearselection = year;
	}
	
	public void setMonthSelection(int month) {
		this.monthselection = month;
	}

	public void setDaySelection(int day) {
		this.dayselection = day;
	}


}
